// ==UserScript==
// @name         通用动漫网站广告过滤
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  try to take over the world!
// @author       You
// @match        https://www.91m.cc/*
// @match        https://v.pptv.com/show/*
// @icon         https://www.google.com/s2/favicons?domain=91m.cc
// @grant        none
// ==/UserScript==

(async function() {
    'use strict';

    // Your code here...

    function hideAds() {
        console.log('%chiding ads...', 'color: green');
        if (!document.getElementById('remove-ads-style')) {
            console.log('%chide ads style not found, adding style...', 'color: green');
            const styleEl = document.createElement('style');
            styleEl.textContent = `
    video { width: 100%; }
    div#playbox {
      height: 100%;
    }
    div.area, div.bofang { width: 1280px; height: auto; }
    div.play {
      height: auto;
    }
    div#HMcoupletDivleft,
    div#HMcoupletDivright,
    div#HMRichBox,
    .vdtp+a,
    a.vdtp_qq
    {
      display: none!important;
    }
    `;
            styleEl.id = 'remove-ads-style';
            document.head.appendChild(styleEl);
        }
        if (document.querySelector('video.roll-current')) {
            document.querySelector('video.roll-current').remove();
            const video = document.querySelector('video.w-video-player');
            video.controls = true;
            document.body.insertBefore(video, document.getElementById('pptv_analyze_source'));
            window.scrollTo(0, 0);
        }
    }

    const setTimeoutAsync = (fn, timeoutMs) => new Promise(resolve => {
        setTimeout(() => {
            resolve(fn());
        }, timeoutMs);
    });

    let timeout = 100;
    const startTime = Date.now();
    while (Date.now() - startTime < 1 * 60 * 1000 /* 1 minute */) {
        await setTimeoutAsync(hideAds, timeout);
        timeout *= 2;
    }
})();